<?php
header("Content-Type:text/html;charset=utf-8");
session_start();
require '../php_func/mysql.php';
if($_GET["login"]){
	$username=$_GET["username"];
	$result=@mysql_query("select * from users where username='$username'");
	$row=@mysql_fetch_assoc($result) or die(mysql_error());
	$user= $row["username"];
	$mail=$row["mail"];
	$psd=$row["password"];
	if($user!=null){
		if($psd==$_GET["password"]){
			session_start();
			$_SESSION["login"]="$mail";
			echo "ok";
		}else{
			echo "密码错误";
		}
	}else{
		echo "用户名不存在";
	}
}else if($_GET["register"]){
	$_username=$_GET["username"];
	$_password=$_GET["password"];
	$_email=$_GET["email"];
	$result=@mysql_query("select * from users where username='$_email'");
	if(mysql_num_rows($result)>0){
		echo "该邮箱已经占用";
	}else{
		$result=@mysql_query("select * from users where username='$_username'");
		if(mysql_num_rows($result)>0){
			echo "用户名已经存在";
		}else{
			$result=@mysql_query("insert into users (username,password,mail) values('$_username','$_password','$_email')");
			mkdir("../user/$_email");
			mkdir("../user/$_email/mp3");
			mkdir("../user/$_email/img");
			$filepath="../user/$_email/love.xml";
			$file=fopen($filepath, "a");
$xml=<<<XML
<?xml version="1.0" encoding="UTF-8"?>
<root>		
</root>
XML;
			fwrite($file, $xml);
			fclose($file);
			echo "ok";
		}
	}
}else if($url=$_GET["current_page"]){//保存当前页面
	$_SESSION["current_page"]=$url;
	echo "ok";
}else if($url=$_GET["logout"]){//注销当前页面
	unset($_SESSION["login"]);
	echo "ok";
}
mysql_close();
?>